import React from 'react';
import { useHistory } from 'react-router-dom';
import { Space, Button } from 'antd';
import Area from './Area';

/**
 * 底部区域
 */
function FooterArea(props) {
    const { edit, submitting, onSubmit } = props;

    const history = useHistory();

    const renderBack = () => {
        return (
            <Button
                onClick={() => {
                    history.push('/resource/acceptance');
                }}
            >
                取消
            </Button>
        );
    };

    const renderSave = () => {
        return (
            <Button
                loading={submitting}
                onClick={() => {
                    onSubmit(true);
                }}
            >
                保存为草稿
            </Button>
        );
    };

    const renderSubmit = () => {
        return (
            <Button
                type="primary"
                loading={submitting}
                onClick={() => {
                    onSubmit(false);
                }}
            >
                提交工单
            </Button>
        );
    };

    return (
        <Area>
            <Space>
                {renderBack()}
                {edit && renderSave()}
                {renderSubmit()}
            </Space>
        </Area>
    );
}

export default FooterArea;
